package com.duzhenwen.demo.controller;

import java.util.List;
import com.duzhenwen.demo.mapper.UserMapper;
import com.duzhenwen.demo.model.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(description = "测试demo")
@RestController
public class DemoController {
	
	@Autowired
	private UserMapper userMapper;
	@ApiOperation(value="获得所有用户", notes = "获得用户的信息")
	@GetMapping("/getUsers")
	public List<User> getUsers() {
		List<User> users=userMapper.getAll();
		return users;
	}
	
    @PostMapping("/getUser")
    public User getUser(Long id) {
    	User user=userMapper.getOne(id);
        return user;
    }
    
    @PostMapping("/add")
    public void save(User user) {
    	userMapper.insert(user);
    }
    
    @PostMapping(value="update")
    public void update(User user) {
    	userMapper.update(user);
    }

    
    
    @PostMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
    	userMapper.delete(id);
    }
    
    
}